<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据可视化测试</title>
    <style type="text/css">
        html {
            height: 100%;
            margin: 0;
        }

        body {
            height: 100%;
            margin: 0;
        }
    </style>
    <link rel='stylesheet' media='all' href="/assets/vendors/layui/css/layui.css"/>
    <script type="text/javascript" src="/assets/vendors/layui/layui.all.js"></script>
    <!-- Favicons -->
    <link rel="shortcut icon" href="/assets/images/logo/logo.png"/>

</head>
<body>
<blockquote class="layui-elem-quote" style="padding: 15px 0% 15px 5%;border-left: hidden">
    <h1 style="font-size: 24px">ENN 认知门户 TIY</h1>
</blockquote>
<button id="urltest" type="button" class="layui-btn" style="margin: 0px 0px 10px 5%;">测试代码
</button>
<div id="maindiv" style="margin:0 5%;height: 75%">
<textarea id="contains" style="height: 100% ;width: 35%;outline:none;"></textarea>

    <iframe name="content_frame" marginwidth=0 marginheight=0 width="60%" height="100%" frameborder=0
            style="border: 1px solid black;"></iframe>
</div>
<blockquote class="layui-elem-quote" style="padding: 15px 0% 15px 5%;border-left: hidden;margin-top: 10px;margin-bottom: 0;">
    <h1 style="font-size: 16px">请在上面的文本框中编辑您的代码，然后单击提交按钮测试结果。</h1>
</blockquote>
</body>
<script type="text/javascript" src="/assets/js/jquery.min.js"></script>
<script type="text/javascript" src="/assets/vendors/layui/layui.all.js"></script>
<script type="text/javascript" src="/assets/js/common.js"></script>
<script type="text/javascript">
    var url;
//    var url1 = 'http://localhost:8081/jsp/mychart.jsp';
//    var url2 = 'http://localhost:8081/jsp/mymap.jsp';
    var url1 = 'http://10.38.240.30:6002/jsp/mychart.jsp';
    var url2 = 'http://10.38.240.30:6002/jsp/mymap.jsp';
    $('#maindiv').height($(window).height()-52-10-38-10-52-10);
    window.onresize=function () {
        $('#maindiv').height($(window).height()-52-10-38-10-52-10);
    }
    if (request.QueryString("f")==null||request.QueryString("f")=='null'){
    }else{
        if(parseInt(request.QueryString("f"))>29){
           url=url2;
        }else{
            url=url1;
        }
        $('#contains').val(formatJson(getParam(request.QueryString("f"))));
    }

    $.extend({
        StandardPost: function (name, url, args) {
            form = $("<form method='post' target='" + name + "' ></form>"),
                form.attr({"action": url});
            $.each(args, function (key, value) {
                input = $("<input type='hidden'>");
                input.attr({"name": key});
                input.val(value);
                form.append(input);
            });

            form.appendTo(document.body);
            form.submit();
            document.body.removeChild(form[0]);
        }
    });
    $('#urltest').click(function () {
        var json = $('#contains').val();
        console.info(json + " , " + url);
        $.StandardPost('content_frame', url, {json: json});
    });
    $('#urltest').click();
    function repeat(s, count) {
        return new Array(count + 1).join(s);
    }

    function formatJson(data) {

        var json= data;

        var i           = 0,
            len          = 0,
            tab         = "    ",
            targetJson     = "",
            indentLevel = 0,
            inString    = false,
            currentChar = null;


        for (i = 0, len = json.length; i < len; i += 1) {
            currentChar = json.charAt(i);

            switch (currentChar) {
                case '{':
                case '[':
                    if (!inString) {
                        targetJson += currentChar + "\n" + repeat(tab, indentLevel + 1);
                        indentLevel += 1;
                    } else {
                        targetJson += currentChar;
                    }
                    break;
                case '}':
                case ']':
                    if (!inString) {
                        indentLevel -= 1;
                        targetJson += "\n" + repeat(tab, indentLevel) + currentChar;
                    } else {
                        targetJson += currentChar;
                    }
                    break;
                case ',':
                    if (!inString) {
                        targetJson += ",\n" + repeat(tab, indentLevel);
                    } else {
                        targetJson += currentChar;
                    }
                    break;
                case ':':
                    if (!inString) {
                        targetJson += ": ";
                    } else {
                        targetJson += currentChar;
                    }
                    break;
                case ' ':
                case "\n":
                case "\t":
                    if (inString) {
                        targetJson += currentChar;
                    }
                    break;
                case '"':
                    if (i > 0 && json.charAt(i - 1) !== '\\') {
                        inString = !inString;
                    }
                    targetJson += currentChar;
                    break;
                default:
                    targetJson += currentChar;
                    break;
            }
        }
        return targetJson;
    }

</script>

</html>





